package com.easylinkin.linkappapi.progress.entity.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.easylinkin.linkappapi.progress.entity.ProgressImageSet;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 进度管理-形象进度设置
 * </p>
 *
 * @author kanyuanfeng
 * @since 2023-11-20
 */
@Data
public class ProgressImageSetVo extends ProgressImageSet {
    /**
     * 名称
     */
    private String name;
    /**
     * 缓存一份材料类别集合
     */
    private static Map<String, List<ProgressImageSetVo>> cacheMap = new HashMap<>();

    private ProgressImageSetVo() {
    }

    private ProgressImageSetVo(String code, String name) {
        this.setCode(code);
        this.name = name;
        this.setIsShow(1);
        this.setComputeType(1);
    }

    /**
     * 获取所有的材料类别
     * @return
     */
    public static List<ProgressImageSetVo> getprogressImageList(){
        //先判断map里有没有
        List<ProgressImageSetVo> list = cacheMap.get("list");
        if (CollectionUtil.isEmpty(list)){
            list = new ArrayList<>();
            ProgressImageSetVo progressImage01 = new ProgressImageSetVo("01","地基与基础");
            ProgressImageSetVo progressImage02 = new ProgressImageSetVo("02","主体结构");
            ProgressImageSetVo progressImage03 = new ProgressImageSetVo("03","装饰装修");
            ProgressImageSetVo progressImage04 = new ProgressImageSetVo("04","屋面工程");
            ProgressImageSetVo progressImage05 = new ProgressImageSetVo("05","给水排水供暖");
            ProgressImageSetVo progressImage06 = new ProgressImageSetVo("06","通风与空调");
            ProgressImageSetVo progressImage07 = new ProgressImageSetVo("07","建筑电气");
            ProgressImageSetVo progressImage08 = new ProgressImageSetVo("08","建筑节能");
            list.add(progressImage01);list.add(progressImage02);list.add(progressImage03);list.add(progressImage04);
            list.add(progressImage05);list.add(progressImage06);list.add(progressImage07);list.add(progressImage08);
            cacheMap.put("list",list);
        }
        return BeanUtil.copyToList(list,ProgressImageSetVo.class);
    }

    /**
     * 通过code值获取name
     */
    public static String getName(String codeData){
        ProgressImageSetVo progressImageSetVo = getprogressImageList().stream().filter(c -> c.getCode().equals(codeData)).findFirst().orElse(new ProgressImageSetVo());
        return progressImageSetVo.getName();
    }

    /**
     * 通过name值获取code
     */
    public static String getCode(String nameData){
        ProgressImageSetVo progressImageSetVo = getprogressImageList().stream().filter(c -> c.getCode().equals(nameData)).findFirst().orElse(new ProgressImageSetVo());
        return progressImageSetVo.getCode();
    }
}
